﻿using Future.Common.Models;
using Future.IDAL;
using Future.Model.DtoModel;
using Future.Model.SysModel;
using System.Linq.Expressions;

namespace Future.DAL
{
    /// <summary>
    /// 描述：字典数据访问类
    /// 创建人： yangkai
    /// 创建时间：2022/11/21 18:39:35
    /// </summary>
    public class DictDataDAL : BaseDAL<DictDataModel>, IDictDataDAL
    {
        public Task<PageModel<DictDataModel>> SelectPageList(DictDataQueryDto dictDataQueryDto, PageParModel page)
        {
            Expression<Func<DictDataModel, bool>> where = x => true;
            Expression whereExpr = where.Body;

            if (!string.IsNullOrEmpty(dictDataQueryDto.DictType))
            {
                Expression<Func<DictDataModel, bool>> dictTypeExpr = x => x.DictType == dictDataQueryDto.DictType;
                whereExpr = Expression.AndAlso(whereExpr, dictTypeExpr.Body);
            }

            if (!string.IsNullOrEmpty(dictDataQueryDto.DictLabel))
            {
                Expression<Func<DictDataModel, bool>> dictLabelExpr = x => x.DictLabel.Contains(dictDataQueryDto.DictLabel);
                whereExpr = Expression.AndAlso(whereExpr, dictLabelExpr.Body);
            }

            if (dictDataQueryDto.Status.HasValue)
            {
                Expression<Func<DictDataModel, bool>> statusExpr = x => x.Status == dictDataQueryDto.Status.Value;
                whereExpr = Expression.AndAlso(whereExpr, statusExpr.Body);
            }

            Expression<Func<DictDataModel, bool>> lambda = Expression.Lambda<Func<DictDataModel, bool>>(whereExpr, where.Parameters);
            return PageListAsync(lambda, page, "DictSort");
        }
    }
}
